package cc.rengu.igas.bomp.common.dao.impl;

import cc.rengu.igas.bomp.common.dao.BompDirectMchntBaseInfoMapper;
import cc.rengu.igas.bomp.common.entity.DirectMchntBaseInfo;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.utility.util.DbsUtil;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.cache.UnifiedCache;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

/**
 * 直联商户基础信息表
 * Created by xubh on 2020/7/7
 */
public class BompDirectMchntBaseInfoMapperImpl implements BompDirectMchntBaseInfoMapper {
    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());
    private String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MCMP_POOL_NAME);

    @Override
    public DirectMchntBaseInfo selectBompDirectMchntBaseInfoNum(String instId, String mchntNo, String status) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MCMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectBompDirectMchntBaseInfoNum");
        DirectMchntBaseInfo directMchntBaseInfo = new DirectMchntBaseInfo();
        directMchntBaseInfo.setInstId(instId);
        directMchntBaseInfo.setMchntCd(mchntNo);
        directMchntBaseInfo.setMchntStatus(status);
        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, directMchntBaseInfo, directMchntBaseInfo);
        if (0 != iReturnCode) {
            rglog.error("获取直联商户基础信息表失败,instId:<{}>,mchntNo:<{}>,iReturnCode:<{}>", instId, iReturnCode);
            return null;
        }
        return directMchntBaseInfo;
    }
}
